Support for "-symbolic-map" to automatically generate symbolic name tables for enumeration [Clang] #117
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes issue #21 "to create an automatic symbolic map for enum values."
[Clang] Add support for
-symbolic-mapto automatically generate symbolic name tables for enumeratorsSummary
This patch introduces a new Clang option
-symbolic-mapthat enables automatic generation of global string name tables for C/C++ enumerators. When this flag is enabled, Clang emits a global variable for each named, defined enum (includingenum classandenum struct), mapping enumerator values to their symbolic string names.Example
Given the enum:
enum Day { Monday, Tuesday, Wednesday };Clang will emit the following global variable into the object file:
The symbol
__nameof_Daywill be available in the object file and can be inspected vianmorobjdump.Implementation
CodeGenModule.cpp
EmitEnumSymbolicMap(const EnumDecl *ED)to emit a global constant array of string literals for the enumerator names.GetAddrOfConstantCStringto obtain LLVM constant string pointers.WeakODRlinkage and pointer-aligned.CodeGenModule.h
Options.td
Introduced a new frontend flag:
LangOptions.def
Added a new language option:
Logic Summary
The symbolic map is generated only if:
Scoped and unscoped enums are both supported.
Symbol Emission
For the following enum:
The object file will contain a global variable named:
Output:
